package com.ymkj.testdemo;

import cn.hutool.http.HttpUtil;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.sun.deploy.net.HttpUtils;
import sun.net.www.http.HttpClient;

import java.io.File;
import java.io.FileOutputStream;

public class Lottery {


    public static void main(String[] args){
        File file  = new File("./data.txt");
        try{
            FileOutputStream out = new FileOutputStream(file);
            for(int i = 2020; i <= 2021; i++){
                for(int j = 1; j < 114; j++){
                    String str = "";
                    if(j<10){
                        str = String.valueOf(i)+"00"+String.valueOf(j);
                    }else if(j>=10&& j<100){
                        str = String.valueOf(i)+"0"+String.valueOf(j);
                    }else{
                        str = String.valueOf(i)+String.valueOf(j);
                    }
                    String result = HttpUtil.get("https://www.cjcp.com.cn/ajax_kj.php?jsoncallback=jsonp16318292&dlt_qs="+str);
                    String[] tempStr = null;
                    if(!StringUtils.isBlank(result)){
                        tempStr = result.split("\\*");
                    }
                    System.out.println("result:"+result);
                    if(tempStr != null && tempStr.length > 10){
                        String data = str+","+tempStr[4]+","+tempStr[5]+","+tempStr[6]+","+tempStr[7]+","+tempStr[8]+","+tempStr[9]+","+tempStr[10]+"\n";
                        out.write(data.getBytes());
                    }
                }
            }
        }catch (Exception e){
            System.out.println("异常："+e);
        }
    }
}